package com.web.dao;

import com.web.entity.Address;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

/**
 * @author FDjavaone
 */
public interface AddressMapper {

    @Delete({
            "delete from t_address",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
            "insert into t_address (m_id, name,",
            " phone, province, ",
            " city, region, street, ",
            " address, default_status, ",
            " create_time, modify_time)",
            " values (#{mId,jdbcType=BIGINT}, #{name,jdbcType=VARCHAR}, ",
            " #{phone,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, ",
            " #{city,jdbcType=VARCHAR}, #{region,jdbcType=VARCHAR}, #{street,jdbcType=VARCHAR}, ",
            " #{address,jdbcType=VARCHAR}, #{defaultStatus,jdbcType=INTEGER}, ",
            " #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insert(Address record);

    @InsertProvider(type = AddressSqlProvider.class, method = "insertSelective")
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "id", before = false, resultType = Long.class)
    int insertSelective(Address record);


    @Select({
            "select",
            " id, m_id, name, phone, province, city, region, street, address, default_status, ",
            " create_time, modify_time",
            " from t_address",
            " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
            @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region", property = "region", jdbcType = JdbcType.VARCHAR),
            @Result(column = "street", property = "street", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "default_status", property = "defaultStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    Address selectByPrimaryKey(Long id);

   
    @UpdateProvider(type = AddressSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Address record);

    @Update({
            "update t_address",
            " set m_id = #{mId,jdbcType=BIGINT},",
            " name = #{name,jdbcType=VARCHAR},",
            " phone = #{phone,jdbcType=VARCHAR},",
            " province = #{province,jdbcType=VARCHAR},",
            " city = #{city,jdbcType=VARCHAR},",
            " region = #{region,jdbcType=VARCHAR},",
            " street = #{street,jdbcType=VARCHAR},",
            " address = #{address,jdbcType=VARCHAR},",
            " default_status = #{defaultStatus,jdbcType=INTEGER},",
            " create_time = #{createTime,jdbcType=TIMESTAMP},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Address record);

    @Update({
            "update t_address",
            " set default_status = #{defaultStatus,jdbcType=INTEGER},",
            " modify_time = #{modifyTime,jdbcType=TIMESTAMP}",
            " where m_id = #{mId,jdbcType=BIGINT}"
    })
    int setAllAddressNotDefault(Address record);

    @Select({
            "select",
            " id, m_id, name, phone, province, city, region, street, address, default_status, ",
            " create_time, modify_time",
            " from t_address",
            " where m_id = #{mId,jdbcType=BIGINT}"
    })
    @Results({
            @Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true),
            @Result(column = "m_id", property = "mId", jdbcType = JdbcType.BIGINT),
            @Result(column = "name", property = "name", jdbcType = JdbcType.VARCHAR),
            @Result(column = "phone", property = "phone", jdbcType = JdbcType.VARCHAR),
            @Result(column = "province", property = "province", jdbcType = JdbcType.VARCHAR),
            @Result(column = "city", property = "city", jdbcType = JdbcType.VARCHAR),
            @Result(column = "region", property = "region", jdbcType = JdbcType.VARCHAR),
            @Result(column = "street", property = "street", jdbcType = JdbcType.VARCHAR),
            @Result(column = "address", property = "address", jdbcType = JdbcType.VARCHAR),
            @Result(column = "default_status", property = "defaultStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.TIMESTAMP),
            @Result(column = "modify_time", property = "modifyTime", jdbcType = JdbcType.TIMESTAMP)
    })
    List<Address> selectByMid(Long aLong);
}